package com.javastudy.jdkfeature.jdk7.file;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.stream.Stream;

/**
 * 遍历单个目录，它不会遍历整个目录。
 */
public class WalkingCurrentPath {
    public static void main(String[] args) {
        String pathName = "E:\\OpenSources\\MyProjects";
        Path dir = Paths.get(pathName);
        try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir)){
            for(Path e : stream){
                System.out.println(e.getFileName());
            }
        }catch(IOException e){

        }

        try (Stream<Path> stream = Files.list(Paths.get(pathName))){
            Iterator<Path> ite = stream.iterator();
            while(ite.hasNext()){
                Path pp = ite.next();
                System.out.println(pp.getFileName());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
